<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys,
                 org.apache.struts.util.ResponseUtils,
                 com.actimind.actitime.beans.TaskBean,
                 com.actimind.actitime.util.TimeUtils,
                 com.actimind.actitime.task.TaskEditForm,
                 com.actimind.actitime.task.TaskEditAction,
                 com.actimind.actitime.task.ViewTaskDetailsAction"%><%@ page errorPage="/error.jsp" %><%

TaskBean task = (TaskBean)session.getAttribute(Keys.TASK_KEY);

%>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Edit Completed Task</title>

    <link rel="stylesheet" href="../css/at.css" type="text/css">

    <script language="JavaScript" src="../js/at.js"></script>
    <script language="JavaScript">
    function doSubmit(f)
    {
        /*if (!checkField(f.name, "Task name is empty", "isNotEmpty"))
            return false;

        trimAllTextFields(f);
        normalizeAllTextFields(f);*/

        return true;
    }

    </script>
    <script language="JavaScript" src="../js/calendar.js"></script>
    <script language="JavaScript" src="<html:rewrite page='/js/task_edit.js?r=1'/>"></script>
    <script language="JavaScript">

    function popupCalendar(date, query)
    {
       var url = '<html:rewrite page="/calendar.do" />?';
       var cWnd = window.open(url + query + '&dateStr=' + date, 'popup', 'width=223,height=320,scrollbars=no,status=no,resizable=no,top=200,left=200');
       cWnd.opener = self;
       cWnd.focus();
    }
    </script>

    <link rel="stylesheet" href="../css/at.css" type="text/css">
    <link rel="stylesheet" href="../css/calendar.css" type="text/css">
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="tasks" />
    <jsp:param name="pageAction" value="taskedit" />
</jsp:include>

<html:form scope="session" action="/tasks/ctaskedit.do" method="post" onsubmit="return doSubmit(this)">

<input type="hidden" name="submitted" value="1" />

<html:hidden property="taskId" />
<html:hidden property="billable" />
<html:hidden property="completed" />

<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff" width="770">
<tr>
    <td class="pagetitle">
        Edit Completed Task
    </td>
</tr>
<tr>
    <td class="formbuttonpane">
        <table cellspacing="0" cellpadding="3" align="center" valign="top" border="0" width="100%">
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                You have selected task:
            </td>
            <td class="formblocktitle">
                <span class="textemphasis"><%=ResponseUtils.filter(task.getName())%></span>
            </td>
        </tr>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Task status:
            </td>
            <td class="formfieldtitle">
            <%
                if (task.isCompleted())
                {
            %>
                <span class="textemphasis" style="color: #000000;">Completed</span>
            <%
                }
                else
                {
            %>
                <span class="textemphasis" style="color: #008100;">Open</span>
            <%
                }
            %>
            </td>
        </tr>
        <%
            if (task.isCompleted())
            {
        %>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Completion date:
            </td>
            <td class="formfieldtitle">
                <span class="textemphasis" style="color: #000000;"><%=task.getCompletionDate("MMM dd, yyyy")%></span>
            </td>
        </tr>
        <%
            }
        %>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Project:
            </td>
            <td class="formfieldtitle">
                <span class="text"><%=ResponseUtils.filter(task.getProject().getName())%></span>
            </td>
        </tr>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Customer:
            </td>
            <td class="formfieldtitle">
                <span class="text"><%=ResponseUtils.filter(task.getProject().getCustomer().getName())%></span>
            </td>
        </tr>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Task creation date:
            </td>
            <td class="formfieldtitle">
                <span class="text"><%=task.getPrintableCreationDate()%></span>
            </td>
        </tr>
        <tr>
            <td class="formblocktitle" width="22%" nowrap="1">
                Last time-track date:
            </td>
            <td class="formfieldtitle">
                <span class="text"><bean:write name="task" property="printableLastTTDate"/></span>
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td class="pagetitle">
        <at:errors />
        <at:messages id="message" message="true">
            <span class="successmsg"><bean:write name="message"/></span>
        </at:messages>
    </td>
</tr>
<tr>
    <td>
        <table cellspacing="0" cellpadding="0" align="left" valign="top" border="0" bgcolor="#ffffff">
        <tr>
            <td colspan="2" class="formcomment">
                <span class="formfieldtitlereq">*</span> Indicates a required field.
            </td>
        </tr>
        <tr>
            <td colspan="2"><img height="10" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="2" class="formblocktitle">
                Edit Task Information
            </td>
        </tr>
        <tr>
            <td colspan="2"><img height="10" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td>
                <img height="1" width="35" src="../img/pixel.gif" />
            </td>
            <td>
                <table cellspacing="0" cellpadding="3" align="left" valign="top" border="0" bgcolor="#ffffff">
            <%
                if (task.isCompleted())
                {
            %>
                <tr>
                    <td class="formfieldtitlereq">
                        *
                    </td>
                    <td class="formfieldtitle">
                        <logic:messagesPresent property="completionDate"><span class="errormsg">Completion Date:</span></logic:messagesPresent>
                        <logic:messagesNotPresent property="completionDate">Completion Date:</logic:messagesNotPresent>
                    </td>
                    <td>
                        <html:select property="completionDateMonth">
                            <html:option value="1">January</html:option>
                            <html:option value="2">February</html:option>
                            <html:option value="3">March</html:option>
                            <html:option value="4">April</html:option>
                            <html:option value="5">May</html:option>
                            <html:option value="6">June</html:option>
                            <html:option value="7">July</html:option>
                            <html:option value="8">August</html:option>
                            <html:option value="9">September</html:option>
                            <html:option value="10">October</html:option>
                            <html:option value="11">November</html:option>
                            <html:option value="12">December</html:option>
                        </html:select>&nbsp;
                        <html:select property="completionDateDay">
                            <%
                                for (int day = 1; day <= 31; day++)
                                {
                        %><html:option value="<%=(new Integer(day)).toString()%>"><%=(day < 10 ? "0" : "")%><%=day%></html:option>
                        <%
                                }
                        %>
                        </html:select>&nbsp;
                        <%
                                int yearFrom = TimeUtils.getStartYearForDropDown();
                                int yearTo = TimeUtils.getEndYearForDropDown(0);
                        %>
                        <html:select property="completionDateYear">
                            <%
                                for (int year = yearFrom; year <= yearTo; year++)
                                {
                        %><html:option value="<%=(new Integer(year)).toString()%>"><%=year%></html:option>
                        <%
                                }
                        %>
                        </html:select>
                        <a href="javascript:popupCalendar(getCompletionDate(), 'yearFrom=<%=yearFrom%>&yearTo=<%=yearTo%>&selectDate=selectCompletionDate');"><img src="../img/cal.gif" width="20" height="20" border="0" hspace="0" vspace="0" align="top" alt="Click Here to Pick up the timestamp"></a>
                    </td>
                </tr>
            <%
                }
            %>
                <tr>
                    <td class="formfieldtitlereq">
                        *
                    </td>
                    <td class="formfieldtitle">
                        <logic:messagesPresent property="name"><span class="errormsg">Task Name:</span></logic:messagesPresent>
                        <logic:messagesNotPresent property="name">Task Name:</logic:messagesNotPresent>
                    </td>
                    <td>
                        <html:text property="name" style="width: 470px" maxlength="255" size="57"/>
                    </td>
                </tr>
                <tr>
                    <td class="formfieldtitlereq">
                        &nbsp;
                    </td>
                    <td class="formfieldtitle">
                        <logic:messagesPresent property="deadline"><span class="errormsg">Deadline:</span></logic:messagesPresent>
                        <logic:messagesNotPresent property="deadline">Deadline:</logic:messagesNotPresent>
                    </td>
                    <td>
                        <html:select property="deadlineMonth">
                            <html:option value="0">--</html:option>
                            <html:option value="1">January</html:option>
                            <html:option value="2">February</html:option>
                            <html:option value="3">March</html:option>
                            <html:option value="4">April</html:option>
                            <html:option value="5">May</html:option>
                            <html:option value="6">June</html:option>
                            <html:option value="7">July</html:option>
                            <html:option value="8">August</html:option>
                            <html:option value="9">September</html:option>
                            <html:option value="10">October</html:option>
                            <html:option value="11">November</html:option>
                            <html:option value="12">December</html:option>
                        </html:select>&nbsp;
                        <html:select property="deadlineDay">
                            <html:option value="0">--</html:option>
                            <%
                                for (int day = 1; day <= 31; day++)
                                {
                        %><html:option value="<%=(new Integer(day)).toString()%>"><%=(day < 10 ? "0" : "")%><%=day%></html:option>
                        <%
                                }
                        %>
                        </html:select>&nbsp;
                        <%
                                int yearFrom = TimeUtils.getStartYearForDropDown();
                                int yearTo = TimeUtils.getEndYearForDropDown(1);
                        %>
                        <html:select property="deadlineYear">
                            <html:option value="0">--</html:option>
                            <%
                                for (int year = yearFrom; year <= yearTo; year++)
                                {
                        %><html:option value="<%=(new Integer(year)).toString()%>"><%=year%></html:option>
                        <%
                                }
                        %>
                        </html:select>
                        <span class="text">
                        <a href="javascript:popupCalendar(getDeadline(), 'yearFrom=<%=yearFrom%>&yearTo=<%=yearTo%>&selectDate=selectDeadline');"><img src="../img/cal.gif" width="20" height="20" border="0" hspace="0" vspace="0" align="top" alt="Click Here to Pick up the timestamp"></a>
                        &nbsp;&nbsp;&nbsp;<a href="javascript:clearDeadline();">Clear deadline</a>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td class="formfieldtitlereq">
                    <%
                        if (task.isBillable())
                        {
                    %>
                        *
                    <%
                        }
                        else
                        {
                    %>
                        &nbsp;
                    <%
                        }
                    %>
                    </td>
                    <td class="formfieldtitle">
                        <logic:messagesPresent property="billingTypeId"><span class="errormsg">Billing Type:</span></logic:messagesPresent>
                        <logic:messagesNotPresent property="billingTypeId">Billing Type:</logic:messagesNotPresent>
                    </td>
                    <td class="formfieldtitle">
                        <html:hidden property="billable" />

                    <%
                        if (task.getProject().isBillable())
                        {
                    %>
                        <at:select property="billingTypeId" maxlength="70">
                            <at:option value="0">Non-Billable</at:option>
                            <at:options collection="<%=Keys.TYPES_LIST_KEY%>" property="id" labelProperty="name" />
                        </at:select>
                    <%
                        }
                        else
                        {
                    %>
                        <html:hidden property="billingTypeId" />
                        Non-Billable
                    <%
                        }
                    %>
                    </td>
                </tr>
                <tr>
                    <td class="formfieldtitlereqtop">
                        &nbsp;
                    </td>
                    <td class="formfieldtitletop">
                        <logic:messagesPresent property="description"><span class="errormsg">Task Description:</span></logic:messagesPresent>
                        <logic:messagesNotPresent property="description">Task Description:</logic:messagesNotPresent>
                    </td>
                    <td>
                        <html:textarea property="description" style="width: 470px; height: 120px; " rows="7" cols="55"/>
                    </td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2"><img height="10" width="1" src="../img/pixel.gif" /></td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td>
    <table width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="2" bgcolor="#808080"><html:img page="/img/pixel.gif" height="1" width="1"/></td>
    </tr>
    <tr>
        <td colspan="2"><html:img page="/img/pixel.gif" height="10" width="1"/></td>
    </tr>
    <tr>
        <td width="23%" valign="top"><span class="formfieldtitle">&nbsp;&nbsp;&nbsp;After editing this task:</span></td>
        <td class="formfieldtitle" valign="top">
            <html:radio property="afterSubmittingPage" value="<%=TaskEditAction.RETURN_TO_TASK_DETAILS%>"/>&nbsp;Return to the view task page<br>
            <html:radio property="afterSubmittingPage" value="<%=TaskEditAction.RETURN_TO_TASK_LIST%>"/>&nbsp;Show list of completed tasks
        </td>
    </tr>
    <tr>
        <td colspan="2"><html:img page="/img/pixel.gif" height="10" width="1"/></td>
    </tr>
    </table>
    </td>
</tr>
<tr>
    <td align="center" class="formbuttonpane">
        <input type="submit" value="Save Changes" />
        <img height="1" width="100" src="../img/pixel.gif" />
        <input type="button" value="    Cancel    " onclick="if (confirm('Are you sure you want to cancel changing task?')) document.location.href='<html:rewrite href='<%="task_details.do?taskId=" + task.getId() + "&origin=" + ViewTaskDetailsAction.COMPLETED_TASKS_ORIGIN%>'/>'">
    </td>
</tr>
</table>

</html:form>

</body>
</html>
